//
//  YKEmotionKeyboard.m
//  youkan
//
//  Created by 吴高烽 on 16/4/14.
//  Copyright © 2016年 Honsintech. All rights reserved.
//

#import "YKEmotionKeyboard.h"
#import "YKEmotionListView.h"
#import "YKEmotionTabBar.h"
#import "YKEmotions.h"
#import "MJExtension.h"
@interface YKEmotionKeyboard()<YKEmotionTabBarDelegate>
@property (nonatomic ,weak)UIView *contentView;
@property (nonatomic ,strong)YKEmotionListView *defaultList;
@property (nonatomic ,strong)YKEmotionListView *emojiList;
@property (nonatomic ,strong)YKEmotionListView *lxhList;
@property (nonatomic ,strong)YKEmotionListView *recentList;
@property (nonatomic ,weak)YKEmotionTabBar *emotionTabbar;


@end
@implementation YKEmotionKeyboard
-(YKEmotionListView *)recentList{
    if (!_recentList) {
        _recentList =[[YKEmotionListView alloc]init];
    }
    return _recentList;
}
-(YKEmotionListView *)defaultList{
    if (!_defaultList) {
        _defaultList =[[YKEmotionListView alloc]init];
        NSString *defaultPath=[[NSBundle mainBundle] pathForResource:@"default/info" ofType:@"plist"];
        NSDictionary *defaultDic=[NSDictionary dictionaryWithContentsOfFile :defaultPath];
        NSArray *defaultArr=[YKEmotions objectArrayWithKeyValuesArray:defaultDic[@"emoticon_group_emoticons"]];
        _defaultList.emotions =defaultArr;
    }
    return _defaultList;
}
-(YKEmotionListView *)emojiList{
    if (!_emojiList) {
        _emojiList =[[YKEmotionListView alloc]init];
        NSString *emojiPath=[[NSBundle mainBundle] pathForResource:@"emoji/info" ofType:@"plist"];
        NSDictionary *emojiDic =[NSDictionary dictionaryWithContentsOfFile:emojiPath];
        NSArray *emojiArr =[YKEmotions objectArrayWithKeyValuesArray:emojiDic[@"emoticon_group_emoticons"]];
        _emojiList.emotions =emojiArr;
    }
    return _emojiList;
}
-(YKEmotionListView *)lxhList{
    if (!_lxhList) {
        _lxhList =[[YKEmotionListView alloc]init];
        NSString *lxhPath=[[NSBundle mainBundle] pathForResource:@"lxh/info.plist" ofType:nil];
        NSDictionary *lxhDic =[NSDictionary dictionaryWithContentsOfFile:lxhPath];
        NSArray *lxhArr =[YKEmotions objectArrayWithKeyValuesArray:lxhDic[@"emoticon_group_emoticons"]];
        _lxhList.emotions =lxhArr;
    }
    return _lxhList;
}
-(instancetype)initWithFrame:(CGRect)frame{
    if (self =[super initWithFrame:frame]) {
        [self setUpAllChilen];
    }
    return self;
}
-(void)setUpAllChilen{
//    表情内容
    UIView *contentView=[[YKEmotionListView alloc]init];
    [self addSubview:contentView];
    self.contentView =contentView ;
//    self.emotionList =emotionList;
    //tabbar
    YKEmotionTabBar *tabbar =[[YKEmotionTabBar alloc]init];
    tabbar.backgroundColor =[UIColor redColor];
    tabbar.delegate =self;
    [self addSubview:tabbar];
    self.emotionTabbar= tabbar;
}
#pragma mark -YKEmotionTabBarDelegate
-(void)emtionTabBar:(YKEmotionTabBar *)emotionTabbar didSelectedButton:(YKEmotionTabBarType)type{
    [self.contentView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    switch (type) {
        case YKEmotionTabBarTypeReccent: //最近 default
        {
            [self.contentView addSubview:self.recentList];
            YKLog(@"最近");
            
        }
            break;
        case YKEmotionTabBarTypeDefault: //默认
        {
            [self.contentView addSubview:self.defaultList];
            YKLog(@"默认");
        }
            break;
        case YKEmotionTabBarTypeEmoji: //emoji
        {
     
            [self.contentView addSubview:self.emojiList];
        
        }
            break;
        case YKEmotionTabBarTypeLXH: //浪小花
        {   YKLog(@"小花");
            [self.contentView addSubview:self.lxhList];
        }
            break;
        default:
            break;
    }
    [self setNeedsLayout];

}
-(void)layoutSubviews{
    [super layoutSubviews];
//    表情栏工具条的位置
    self.emotionTabbar.width =self.width;
    self.emotionTabbar.height =37;
    self.emotionTabbar.x =0;
    self.emotionTabbar.y =self.height -self.emotionTabbar.height;
//    表情视图的位置
    self.contentView.width  =self.width;
    self.contentView.x =0;
    self.contentView.y =0;
    self.contentView.height =self.emotionTabbar.y;
    
    UIView *chiled =[self.contentView.subviews lastObject];
    chiled.frame =self.contentView.bounds;
}


@end
